package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import java.util.*;

//////////////////////////////////////////////////////////////////////////
//// MoCDialog
/**
 
@author Ivan Jeukens
@version v 0.1 30/01/2002
*/
public class MoCDialog extends JDialog {
    
    public MoCDialog(Frame parent) {
        super(parent, true);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());

        JPanel buttonPanel = new JPanel();

        JButton button = new JButton("Ok");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                hide();
	    }
        });
        buttonPanel.add(button);

        _boxPanel = new JPanel();
        JScrollPane sp = new JScrollPane(_boxPanel);
        panel.add(sp, BorderLayout.CENTER);

        panel.add(buttonPanel, BorderLayout.SOUTH);

        getContentPane().add(panel);

        setSize(350,200);
        setTitle("Enabled Models of Computation");
        
        setModal(true);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void setMoCs(LinkedList names) {
        _boxes = new JCheckBox[names.size()];
        for(int i = 0;i < names.size();i++) {
            _boxes[i] = new JCheckBox((String)names.get(i));
            _boxPanel.add(_boxes[i]);
        }
    }
    
    public boolean getState(String moc) {
        for(int i = 0;i < _boxes.length;i++) {
            if(_boxes[i].getText().equals(moc)) {
                return _boxes[i].isSelected();
            }
        }
        return false;
    }    
    
    public LinkedList getSelectedMoCs() {
        LinkedList ret = new LinkedList(); 
        for(int i = 0;i < _boxes.length;i++) {
            if(_boxes[i].isSelected()) {
                ret.add(_boxes[i].getText());
            }
        }
        return ret;
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////
    
    
    ///////////////////////////////////////////////////////////////////
    ////                      private variables                    ////
    
    private JPanel _boxPanel;
    private JCheckBox [] _boxes;
}
